load("data_for_analysis.rdata")

library(tidyverse)
library(rms)
library(stargazer)
library(ggpubr)

#### Table 1 ####
m_cmte_H1 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "House"))
m_cmte_H2 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                   halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "House"))
m_cmte_H3 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                   mean_majority_members_nominate_dim1_pres_side + n_cmte_members +
                   halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "House"))
m_cmte_S1 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "Senate"))
m_cmte_S2 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                   halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "Senate"))
m_cmte_S3 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                   n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                   mean_majority_members_nominate_dim1_pres_side + n_cmte_members + halfyear + chamber_committee_name,
                 d_period_cmtes_ARCHV %>%
                   filter(chamber == "Senate"))

stargazer(m_cmte_H1, m_cmte_H2, m_cmte_H3, m_cmte_S1, m_cmte_S2, m_cmte_S3,
          dep.var.labels = "Number of foreign principals lobbying committee",
          column.separate = c(3, 3), column.labels = c("House", "Senate"),
          omit = "chamber_committee_name.*|halfyear.*|factor\\(pres\\).*",
          covariate.labels = c("Number of SAP-drawing bills under consideration",
                               "Number of bills under consideration",
                               "Number of highly significant bills under consideration",
                               "Mean ideology of majority contingent",
                               "Committee size"),
          add.lines = list(c("Committee FEs", rep("Y", 6)),
                           c("Period FEs", rep("Y", 6))),
          df = F, digits = 2, notes.append = F, type = "text")

#### Table 2 ####
m_cmte_member_H1 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "House"))
m_cmte_member_H2 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "House"))
m_cmte_member_H3 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                          cmte_foreign_aff + majority + same_party_as_pres + nominate_dim1_pres_side +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "House"))
m_cmte_member_S1 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "Senate"))
m_cmte_member_S2 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "Senate"))
m_cmte_member_S3 <- ols(n_FARA_principals ~ n_bills_with_preceding_SAPs_FP +
                          n_bills_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP +
                          cmte_foreign_aff + majority + same_party_as_pres + nominate_dim1_pres_side +
                          halfyear + icpsr,
                        d_period_cmte_members_ARCHV %>%
                          filter(chamber == "Senate"))

stargazer(m_cmte_member_H1, m_cmte_member_H2, m_cmte_member_H3, m_cmte_member_S1, m_cmte_member_S2, m_cmte_member_S3,
          column.separate = c(3, 3), column.labels = c("House", "Senate"),
          dep.var.labels = "Number of foreign principals lobbying committee member",
          omit = "icpsr.*|halfyear.*|^pres.*",
          covariate.labels = c("Number of SAP-drawing bills under consideration",
                               "Number of bills under consideration",
                               "Number of highly significant bills under consideration",
                               "Member of foreign affairs committee",
                               "Member of chamber majority",
                               "Member of president's party",
                               "Ideology"),
          add.lines = list(c("Legislator FEs", rep("Y", 6)),
                           c("Period FEs", rep("Y", 6))),
          df = F, digits = 2, notes.append = F, type = "text")

#### Table 3 ####
m_MC_Clinton1 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                      n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                      factor(icpsr),
                    d_period_MCs_ARCHV %>%
                      filter(pres == 42))
m_MC_Clinton2 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                      n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                      cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                      factor(icpsr),
                    d_period_MCs_ARCHV %>%
                      filter(pres == 42))
m_MC_Bush1 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP + 
                   n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                   factor(icpsr),
                 d_period_MCs_ARCHV %>%
                   filter(pres == 43))
m_MC_Bush2 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                   n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                   cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                   factor(icpsr),
                 d_period_MCs_ARCHV %>%
                   filter(pres == 43))
m_MC_Obama1 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP + 
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 44))
m_MC_Obama2 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                    cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber + 
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 44))
m_MC_Trump1 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP + 
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 45))
m_MC_Trump2 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                    cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 45))
m_MC_Biden1 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP + 
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 46))
m_MC_Biden2 <- lm(n_FARA_principals ~ n_bills_floor_FP_with_SAP +
                    n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                    cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                    factor(icpsr),
                  d_period_MCs_ARCHV %>%
                    filter(pres == 46))

stargazer(m_MC_Clinton1, m_MC_Clinton2, m_MC_Bush1, m_MC_Bush2, m_MC_Obama1, m_MC_Obama2, m_MC_Trump1, m_MC_Trump2, m_MC_Biden1, m_MC_Biden2,
          dep.var.labels = "Number of foreign principals lobbying legislator",
          omit = "factor\\(icpsr\\).*|halfyear.*|factor\\(pres\\).*",
          covariate.labels = c("Number of SAP-drawing bills on agenda",
                               "Number of bills on agenda",
                               "Number of highly significant bills on agenda",
                               "Member of foreign affairs committee",
                               "Member of president's party",
                               "Member of chamber majority",
                               "Ideology",
                               "Leader",
                               "Senator"),
          column.separate = rep(2, 5), column.labels = c("Clinton", "G.W. Bush", "Obama", "Trump 1", "Biden"),
          add.lines = list(c("Legislator FEs", rep("Y", 10))),
          df = F, digits = 2, notes.append = F, type = "text")

#### Table 4 ####
m_MC_non_Clinton <- lm(n_FARA_registrants_non ~ n_bills_floor_FP_with_SAP +
                         n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                         cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                         factor(icpsr),
                       d_period_MCs_ARCHV %>%
                         filter(pres == 42))
m_MC_top_Clinton <- lm(n_FARA_registrants_top100 ~ n_bills_floor_FP_with_SAP +
                         n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor +
                         cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                         factor(icpsr),
                       d_period_MCs_ARCHV %>%
                         filter(pres == 42))
m_MC_non_Bush <- lm(n_FARA_registrants_non ~ n_bills_floor_FP_with_SAP +
                      n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                      cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                      factor(icpsr),
                    d_period_MCs_ARCHV %>%
                      filter(pres == 43))
m_MC_top_Bush <- lm(n_FARA_registrants_top100 ~ n_bills_floor_FP_with_SAP +
                      n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                      cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                      factor(icpsr),
                    d_period_MCs_ARCHV %>%
                      filter(pres == 43))
m_MC_non_Obama <- lm(n_FARA_registrants_non ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 44))
m_MC_top_Obama <- lm(n_FARA_registrants_top100 ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 44))
m_MC_non_Trump <- lm(n_FARA_registrants_non ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 45))
m_MC_top_Trump <- lm(n_FARA_registrants_top100 ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 45))
m_MC_non_Biden <- lm(n_FARA_registrants_non ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 46))
m_MC_top_Biden <- lm(n_FARA_registrants_top100 ~ n_bills_floor_FP_with_SAP +
                       n_bills_floor_FP + n_bills_CQkey_or_most_lobbied_10_pct_FP_floor + 
                       cmte_foreign_aff + same_party_as_pres + majority + nominate_dim1 + leader + chamber +
                       factor(icpsr),
                     d_period_MCs_ARCHV %>%
                       filter(pres == 46))

stargazer(m_MC_non_Clinton, m_MC_top_Clinton, m_MC_non_Bush, m_MC_top_Bush,
          m_MC_non_Obama, m_MC_top_Obama, m_MC_non_Trump, m_MC_top_Trump,
          m_MC_non_Biden, m_MC_top_Biden,
          dep.var.labels = rep(c("Non-top", "Top"), 5),
          omit = "factor\\(icpsr\\).*|halfyear.*|factor\\(pres\\).*",
          covariate.labels = c("Number of SAP-drawing bills on agenda",
                               "Number of bills on agenda",
                               "Number of highly significant bills on agenda",
                               "Member of foreign affairs committee",
                               "Member of president's party",
                               "Member of chamber majority",
                               "Ideology",
                               "Leader",
                               "Senator"),
          column.separate = rep(2, 5), column.labels = c("Clinton", "G.W. Bush", "Obama", "Trump 1", "Biden"),
          add.lines = list(c("Legislator FEs", rep("Y", 10))),
          df = F, digits = 2, notes.append = F, type = "text")